import Vue from "vue";
import App from "./App.vue";
import Cookie from "./untils/Cookie";
import axios from "./untils";
Vue.prototype.axios = axios;
Vue.prototype.Cookie = Cookie;
Vue.prototype.Url = process.env.VUE_APP_BASE_API;
Vue.prototype.goBack = () => {
  // console.log(history);
  history.go(-1);
};
import ElementUI from "element-ui";
import "element-ui/lib/theme-chalk/index.css";
import router from "./router";
import store from "./store";
import "../public/reset.css";
Vue.use(ElementUI);
Vue.prototype.msg = (res, xx) => {
  // console.log(Vue);
  if (res.code == 1) {
    xx.$message({
      message: res.msg,
      type: "success",
    });
  } else {
    xx.$message({
      message: res.msg,
      type: "warning",
    });
  }
};
Vue.config.productionTip = false;
let vm = new Vue({
  render: (h) => h(App),
  router,
  store,
}).$mount("#app");
router.beforeEach((to, from, next) => {
  // console.log(to);
  let role = vm.$store.state.user.role;
  if (to.meta.needLogin) {
    if (sessionStorage.getItem("token")) {
      next();
    } else {
      // console.log(Cookie.get("token"), "token");
      vm.$message({
        message: "请先登录",
        type: "warning",
      });
      next("/login");
    }
  } else {
    next();
  }
});
